<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增设备管理表')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-Gzmx_device-add">
          <input id="dev_azdw1_name" name="dev_azdw1_name" class="form-control"  style="display: none" type="text">
          <input id="dev_azdw2_name" name="dev_azdw2_name" class="form-control"  style="display: none" type="text">
          <input id="dev_azdw3_name" name="dev_azdw3_name" class="form-control"  style="display: none" type="text">
          <input id="dev_azdw4_name" name="dev_azdw4_name" class="form-control"  style="display: none" type="text">
          <input id="dev_azdw5_name" name="dev_azdw5_name" class="form-control"  style="display: none" type="text">
          <input id="dev_sblx_name" name="dev_sblx_name" class="form-control"  style="display: none" type="text">
          
           
        <!--  
         <div class="form-group">    
                <label class="col-sm-3 control-label">所属单位名称：</label>
                <div class="col-sm-8">
                    <input name="ssdw_name" class="form-control" type="text">
                </div>
            </div>
            
            
           
            <div class="form-group">    
                <label class="col-sm-3 control-label">点位名称：</label>
                <div class="col-sm-8">
                    <input name="Description" class="form-control" type="text">
                </div>
            </div>
        <div class="form-group">    
                <label class="col-sm-3 control-label">安装点位名称1：</label>
                <div class="col-sm-8">
                  
                </div>
            </div>             
            <div class="form-group">    
                <label class="col-sm-3 control-label">安装点位名称2：</label>
                <div class="col-sm-8">
                    <input name="dev_azdw2_name" class="form-control" type="text">
                    
                </div>
            </div>
          
            <div class="form-group">    
                <label class="col-sm-3 control-label">安装点位名称3：</label>
                <div class="col-sm-8">
                    <input name="dev_azdw3_name" class="form-control" type="text">
                   
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">安装点位名称4：</label>
                <div class="col-sm-8">
                    <input name="dev_azdw4_name" class="form-control" type="text">
                    
                    
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">安装点位名称5：</label>
                <div class="col-sm-8">
                    <input name="dev_azdw5_name" class="form-control" type="text">
                </div>
            </div>
            
        
        
        
        
        
        <div class="form-group">    
                <label class="col-sm-3 control-label">设备类型ID：</label>
                <div class="col-sm-8">
                    <input name="dev_sblx_id" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">安装区域ID：</label>
                <div class="col-sm-8">
                    <input name="dev_azqy_id" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">安装点位ID1：</label>
                <div class="col-sm-8">
                    <input name="dev_azdw1_id" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">安装点位ID2：</label>
                <div class="col-sm-8">
                    <input name="dev_azdw2_id" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">安装点位ID3：</label>
                <div class="col-sm-8">
                    <input name="dev_azdw3_id" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">点位ID：</label>
                <div class="col-sm-8">
                    <input name="SourceTag" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">安装点位ID4：</label>
                <div class="col-sm-8">
                    <input name="dev_azdw4_id" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">安装点位ID5：</label>
                <div class="col-sm-8">
                    <input name="dev_azdw5_id" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">单位ID：</label>
                <div class="col-sm-8">
                    <input name="deptId" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">部门ID：</label>
                <div class="col-sm-8">
                    <input name="bm_id" class="form-control" type="text">
                </div>
            </div>
             <div class="form-group">    
                <label class="col-sm-3 control-label">所属单位代码：</label>
                <div class="col-sm-8">
                    <input name="ssdw_dm" class="form-control" type="text">
                </div>
            </div>
             <div class="form-group">    
                <label class="col-sm-3 control-label">部门名称：</label>
                <div class="col-sm-8">
                    <input name="bm_name" class="form-control" type="text">
                </div>
            </div>
            
            <div class="form-group">    
                <label class="col-sm-3 control-label">单位名称：</label>
                <div class="col-sm-3">
                    <input name="dept_name" class="form-control" type="text">
                </div>
                 <label class="col-sm-2 control-label">作业区名称：</label>
                <div class="col-sm-3">
                    <input name="zyq_name" class="form-control" type="text">
                </div>
            </div>
            -->
            
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">设备名称：</label>
                <div class="col-sm-8">
                    <input name="dev_name" id="dev_name" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">规格型号：</label>
                <div class="col-sm-8">
                    <input name="dev_ggxh" id="dev_ggxh" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">生产厂家：</label>
                <div class="col-sm-8">
                    <input name="dev_sccj" id="dev_sccj" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">出厂日期：</label>
                <div class="col-sm-3">
                    <div class="input-group date">
                        <input name="dev_ccrq" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
                <label class="col-sm-2 control-label is-required ">投产日期：</label>
                <div class="col-sm-3">
                    <div class="input-group date">
                        <input name="dev_tcrq" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>            
            <div class="form-group">    
                <label class="col-sm-3 control-label">精度等级：</label>
                <div class="col-sm-3">
                    <input name="dev_jddj" class="form-control" type="text">
                </div>
                 <label class="col-sm-2 control-label">测量范围：</label>
                <div class="col-sm-3">
                    <input name="dev_clfw" class="form-control" type="text">
                </div>
            </div>            
            <div class="form-group">    
                <label class="col-sm-3 control-label">ABC分类：</label>
                <div class="col-sm-3">
                    <select name="dev_abcfl" class="form-control m-b" th:with="type=${@dict.getType('abc_fl')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
                <label class="col-sm-2 control-label">设备状态：</label>
                <div class="col-sm-3">
                    <select name="dev_sbzt" class="form-control m-b" th:with="type=${@dict.getType('sb_zt')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">出厂编号：</label>
                <div class="col-sm-3">
                    <input name="dev_ccbh" class="form-control" type="text">
                </div>
                 <label class="col-sm-2 control-label">仪表编号：</label>
                <div class="col-sm-3">
                    <input name="dev_ybbh" class="form-control" type="text" readonly="true">
                </div>
            </div>            
            <div class="form-group">    
                <label class="col-sm-3 control-label">计划检定日期：</label>
                <div class="col-sm-3">
                    <div class="input-group date">
                        <input name="dev_jhjdrq" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
                 <label class="col-sm-2 control-label">设备类型：</label>
                <div class="col-sm-3">
                  <select id="dev_sblx_id" name="dev_sblx_id" class="form-control m-b" >
                  </select>
                <!-- <input name="dev_sblx_name" class="form-control" type="text"> -->
                    
                </div>
            </div>
             <div class="form-group">    
                <label class="col-sm-3 control-label">是否检定：</label>
                <div class="col-sm-3">
                <select name="dev_isjd" class="form-control m-b" th:with="type=${@dict.getType('sf_jd')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
                </div>
                 <label class="col-sm-2 control-label">是否报废：</label>
                <div class="col-sm-3">
                <select name="dev_isbf" class="form-control m-b" th:with="type=${@dict.getType('sf_jd')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
                </div>
            </div>
            
             
                        <div id="element2" class="row">
                            <div class="col-sm-1" style="align:right">
                                                                                安装点位:
 			                </div>
                            <div class="col-sm-2">
	                            <select name="dev_azdw1_id" id="first" style="width:120px" class="first form-control m-b"></select>
			                </div>
			                <div class="col-sm-2">
				                <select name="dev_azdw2_id" id="second" style="width:120px" class="second form-control m-b"></select>
			                </div> 
			                <div class="col-sm-2">
				                <select name="dev_azdw3_id" id="third" style="width:120px" class="third form-control m-b"></select>
			                </div>
			                <div class="col-sm-2">
				                <select name="dev_azdw4_id" id="fourth" style="width:120px" class="fourth form-control m-b"></select>
			                </div>
			                <div class="col-sm-2">
			                    <select name="dev_azdw5_id" id="fifth" style="width:120px" class="fifth form-control m-b"></select>
			                </div> 
                        </div>  
          
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "Gzmx_device/Gzmx_device"
      //alert(JSON.stringify(result.rows));  
        var roles=[[${currentUser.roles}]];
        var dataScope=roles[0].dataScope;
        var dept_id=[[${currentUser.deptId}]];
        var dept=[[${dept}]];
        var ancestors=dept.ancestors;
        var bm_id=dept.deptId;
       
        if(ancestors.split(",").length>4){
        	dept_id=ancestors.split(",")[4];
        }
        //alert(ancestors);
        //alert(ancestors.split(",").length);
    	//alert(roles[0].dataScope);//.dataScope
        $(function(){
        	initfirst("1");
        	initdev_sblx_name();
        });
        $("#form-Gzmx_device-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
        	var str_dev_name=$("#dev_name").val();   
        	var str_dev_ggxh=$("#dev_ggxh").val();
        	var str_dev_sccj=$("#dev_sccj").val();
        	
        	
        	$("#dev_name").val(str_dev_name.replace(/\s*/g,""));        	 
        	$("#dev_ggxh").val(str_dev_ggxh.replace(/\s*/g,""));
        	$("#dev_sccj").val(str_dev_sccj.replace(/\s*/g,""));
        	
        	var str_dev_sblx_id=$("#dev_sblx_id").val();        	
        	if(str_dev_sblx_id==""){
        		$.modal.alertWarning("未选取设备类型，请核对");
        		return false;
        	}
        	 
        	var str_first=$("#first").val();
        	var str_second=$("#second").val();
        	var str_third=$("#third").val();
        	var str_fourth=$("#fourth").val();
        	var str_fifth=$("#fifth").val();       	
        	 
        	 
        	if(str_first==""||str_second==""||str_third==""||str_fourth==""||str_fifth==""){
        		$.modal.alertWarning("未选取生产点位，请核对");
        		return false;
        	}
        	
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-Gzmx_device-add').serialize());
            }
        }

        $("input[name='dev_ccrq']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='dev_jhjdrq']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='dev_tcrq']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
        
        
        
        function initdev_sblx_name(){
        	//var $provinceSelect = $("#"+objDivId).find('select.provinceId');
        	//var $provinceHid = $("#"+objDivId).find('input.province');
            $.ajax({
                type: "post",
                url: "/gzmx_sblx_fjd/fjd/list_all",
                data: {
                    "id" :"",
                },
                success: function(result) {
                	//alert(JSON.stringify(result.rows));                	 
                    var rows = result.length;
                    //alert(rows);
                    var html = `<option value="">请选择</option>`
                    for (let i = 0; i < result.rows.length; i++) {
                        html+=`<option value="`+result.rows[i].id+`">`+result.rows[i].lx_name+`</option>`
                    }
                    $("#dev_sblx_id").html(html);
                    $("#dev_sblx_id").change(function (){ 
                    	$("#dev_sblx_name").val($(this).find('option:selected').text());                    	
                    	//initsecond($("#first").val());
                    //	$provinceHid.val($provinceSelect.find("option:selected").text());
                    //	provenceChange(objDivId);
                    });
                },
                error: function(error) {
                    $.modal.alertWarning(error);
                }
            });
        }
        function initfirst(objDivId){
        	//var $provinceSelect = $("#"+objDivId).find('select.provinceId');
        	//var $provinceHid = $("#"+objDivId).find('input.province');
            $.ajax({
                type: "post",
                url: "/gzmx_scdw/gzmx_scdw/list",
                data: {
                    "jb" : objDivId,
                },
                success: function(result) {
                	//alert(JSON.stringify(result.length));
                	 console.log(result, 'res');
                    var rows = result.length;
                    //alert(rows);
                    var html = `<option value="">请选择</option>`
                    for (let i = 0; i < result.length; i++) {
                    	if(dataScope==1){
                    		html+=`<option value="`+result[i].id+`">`+result[i].dwmc+`</option>`
                    	}else{
                    		if(result[i].deptId==dept_id){
                    			html+=`<option value="`+result[i].id+`">`+result[i].dwmc+`</option>`
                    		}
                    	}
                       
                      
                    }
                    $("#first").html(html);
                    $("#first").change(function (){ 
                    	$("#dev_azdw1_name").val($(this).find('option:selected').text());                    	
                    	initsecond($("#first").val());
                    //	$provinceHid.val($provinceSelect.find("option:selected").text());
                    //	provenceChange(objDivId);
                    });
                },
                error: function(error) {
                    $.modal.alertWarning(error);
                }
            });
        }
        function initsecond(objDivId){
        	//var $provinceSelect = $("#"+objDivId).find('select.provinceId');
        	//var $provinceHid = $("#"+objDivId).find('input.province');
            $.ajax({
                type: "post",
                url: "/gzmx_scdw/gzmx_scdw/list",
                data: {
                    "fdwdm" : objDivId,
                },
                success: function(result) {
                	//alert(JSON.stringify(result.length));
                	 
                    var rows = result.length;
                    //alert(rows);
                    var html = `<option value="">请选择</option>`;
                   
                    for (let i = 0; i < result.length; i++) {
                    	if(ancestors.split(",").length>4){
                    		 
                    		if(result[i].dept_id_id==bm_id){
                                html+=`<option value="`+result[i].id+`">`+result[i].dwmc+`</option>`

                    		}
                    	}else{
                            html+=`<option value="`+result[i].id+`">`+result[i].dwmc+`</option>`
	
                    	}
                    }
                    $("#second").html(html);
                    $("#second").change(function (){   
                    initthird($("#second").val());
                    $("#dev_azdw2_name").val($(this).find('option:selected').text());  
                    //	$provinceHid.val($provinceSelect.find("option:selected").text());
                    //	provenceChange(objDivId);
                    });
                },
                error: function(error) {
                    $.modal.alertWarning(error);
                }
            });
        }
        
        function initthird(objDivId){
        	//var $provinceSelect = $("#"+objDivId).find('select.provinceId');
        	//var $provinceHid = $("#"+objDivId).find('input.province');
            $.ajax({
                type: "post",
                url: "/gzmx_scdw/gzmx_scdw/list",
                data: {
                    "fdwdm" : objDivId,
                },
                success: function(result) {
                	//alert(JSON.stringify(result.length));
                	 
                    var rows = result.length;
                    //alert(rows);
                    var html = `<option value="">请选择</option>`
                    for (let i = 0; i < result.length; i++) {
                        html+=`<option value="`+result[i].id+`">`+result[i].dwmc+`</option>`
                    }
                    $("#third").html(html);
                    $("#third").change(function (){   
                    	 initfourth($("#third").val());
                    	 $("#dev_azdw3_name").val($(this).find('option:selected').text());  
                    //	$provinceHid.val($provinceSelect.find("option:selected").text());
                    //	provenceChange(objDivId);
                    });
                },
                error: function(error) {
                    $.modal.alertWarning(error);
                }
            });
        }
        function initfourth(objDivId){
        	//var $provinceSelect = $("#"+objDivId).find('select.provinceId');
        	//var $provinceHid = $("#"+objDivId).find('input.province');
            $.ajax({
                type: "post",
                url: "/gzmx_scdw/gzmx_scdw/list",
                data: {
                    "fdwdm" : objDivId,
                },
                success: function(result) {
                	//alert(JSON.stringify(result.length));
                	 
                    var rows = result.length;
                    //alert(rows);
                    var html = `<option value="">请选择</option>`
                    for (let i = 0; i < result.length; i++) {
                        html+=`<option value="`+result[i].id+`">`+result[i].dwmc+`</option>`
                    }
                    $("#fourth").html(html);
                    $("#fourth").change(function (){   
                    	 initfifth($("#fourth").val());
                    	 $("#dev_azdw4_name").val($(this).find('option:selected').text());  
                    //	$provinceHid.val($provinceSelect.find("option:selected").text());
                    //	provenceChange(objDivId);
                    });
                },
                error: function(error) {
                    $.modal.alertWarning(error);
                }
            });
        }
        function initfifth(objDivId){
        	//var $provinceSelect = $("#"+objDivId).find('select.provinceId');
        	//var $provinceHid = $("#"+objDivId).find('input.province');
            $.ajax({
                type: "post",
                url: "/gzmx_scdw/gzmx_scdw/list",
                data: {
                    "fdwdm" : objDivId,
                },
                success: function(result) {
                	//alert(JSON.stringify(result.length));
                	 
                    var rows = result.length;
                    //alert(rows);
                    var html = `<option value="">请选择</option>`
                    for (let i = 0; i < result.length; i++) {
                        html+=`<option value="`+result[i].id+`">`+result[i].dwmc+`</option>`
                    }
                    $("#fifth").html(html);
                    $("#fifth").change(function (){   
                        $("#dev_azdw5_name").val($(this).find('option:selected').text());  
                    	// initfifth($("#fourth").val());
                    //	$provinceHid.val($provinceSelect.find("option:selected").text());
                    //	provenceChange(objDivId);
                    });
                },
                error: function(error) {
                    $.modal.alertWarning(error);
                }
            });
        }
    </script>
</body>
</html>